#!/bin/bash

start_date="2025-01-03"
end_date="2025-01-04"
python_script="/home/swifar/mpilot/code/merger_by_database/run.py"
version="V20250303"
python_bin="/home/software/anaconda3/bin/python"

max_jobs=4
job_count=0

current_date="$start_date"
while [[ "$current_date" <="$end_date" ]]; do
    echo ">>> [$current_date] Running merge"

    $python_bin "$python_script" --date "$current_date" --version "$version" &

    ((job_count++))

    if ((job_count % max_jobs == 0)); then
        wait  # 等待当前批次所有子进程完成
    fi

    current_date=$(date -I -d "$current_date + 1 day")
done

wait  # 等待最后一批完成
